/**
 * 
 */
package com.haizhi.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;

import com.haizhi.bean.TbPost;
import com.haizhi.bean.TbSection;
import com.haizhi.dao.PostDao;
import com.haizhi.service.PostService;

/**
 * @author jiangjintai
 *
 */
@Service("postService")
public class PostServiceImpl extends BaseServiceImpl<TbPost, Integer> implements
		PostService {
	@Autowired
	PostDao postDao;
	/* （非 Javadoc）
	 * @see com.haizhi.service.impl.BaseServiceImpl#getDao()
	 */
	@Override
	protected JpaRepository<TbPost, Integer> getDao() {

		return postDao;
	}
	/* （非 Javadoc）
	 * @see com.haizhi.service.PostService#findByTbSectionSectionId(java.lang.Integer, org.springframework.data.domain.Pageable)
	 */
	@Override
	public Page<TbPost> findByTbSectionSectionId(Integer sectionId,
			Pageable pageAble) {
		// 
		return this.postDao.findByTbSectionSectionId(sectionId,pageAble);
	}
	/* （非 Javadoc）
	 * @see com.haizhi.service.PostService#findByTbSectionSectionIdAndPostType(com.haizhi.bean.TbSection, int, org.springframework.data.domain.Pageable)
	 */
	@Override
	public Page<TbPost> findByTbSectionAndPostType(
			TbSection tbSection, int i, Pageable pageAble) {
		// 
		return this.postDao.findByTbSectionSectionIdAndPostType(tbSection.getSectionId(),i,pageAble);
	}
	/* （非 Javadoc）
	 * @see com.haizhi.service.PostService#saveAndUpdateTbSection(com.haizhi.bean.TbPost)
	 */
	@Override
	public void saveAndUpdateTbSection(TbPost tbPost) {
		// 
		this.save(tbPost);
		tbPost.getTbSection().setSectionPostNum(tbPost.getTbSection().getSectionPostNum()+1);
		tbPost.getTbSection().setSectionTodayPostNum(tbPost.getTbSection().getSectionTodayPostNum()+1);
		this.save(tbPost);
	}



}
